// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Requests;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class UpdateJobRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>Updates certain properties of an anomaly detection job.</para>
/// </summary>
public sealed partial class UpdateJobRequest : PlainRequest<UpdateJobRequestParameters>
{
	public UpdateJobRequest(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningUpdateJob;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.update_job";

	/// <summary>
	/// <para>Advanced configuration option. Specifies whether this job can open when<br/>there is insufficient machine learning node capacity for it to be<br/>immediately assigned to a node. If `false` and a machine learning node<br/>with capacity to run the job cannot immediately be found, the open<br/>anomaly detection jobs API returns an error. However, this is also<br/>subject to the cluster-wide `xpack.ml.max_lazy_ml_nodes` setting. If this<br/>option is set to `true`, the open anomaly detection jobs API does not<br/>return an error and the job waits in the opening state until sufficient<br/>machine learning node capacity is available.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("allow_lazy_open")]
	public bool? AllowLazyOpen { get; set; }
	[JsonInclude, JsonPropertyName("analysis_limits")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimit? AnalysisLimits { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. The time between each periodic persistence<br/>of the model.<br/>The default value is a randomized value between 3 to 4 hours, which<br/>avoids all jobs persisting at exactly the same time. The smallest allowed<br/>value is 1 hour.<br/>For very large models (several GB), persistence could take 10-20 minutes,<br/>so do not set the value too low.<br/>If the job is open when you make the update, you must stop the datafeed,<br/>close the job, then reopen the job and restart the datafeed for the<br/>changes to take effect.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("background_persist_interval")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? BackgroundPersistInterval { get; set; }
	[JsonInclude, JsonPropertyName("categorization_filters")]
	public ICollection<string>? CategorizationFilters { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. Contains custom meta data about the job.<br/>For example, it can contain custom URL information as shown in Adding<br/>custom URLs to machine learning results.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("custom_settings")]
	public IDictionary<string, object>? CustomSettings { get; set; }

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies a period of time (in days)<br/>after which only the first snapshot per day is retained. This period is<br/>relative to the timestamp of the most recent snapshot for this job. Valid<br/>values range from 0 to `model_snapshot_retention_days`. For jobs created<br/>before version 7.8.0, the default value matches<br/>`model_snapshot_retention_days`.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("daily_model_snapshot_retention_after_days")]
	public long? DailyModelSnapshotRetentionAfterDays { get; set; }

	/// <summary>
	/// <para>A description of the job.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("description")]
	public string? Description { get; set; }

	/// <summary>
	/// <para>An array of detector update objects.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("detectors")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Detector>? Detectors { get; set; }

	/// <summary>
	/// <para>A list of job groups. A job can belong to no groups or many.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("groups")]
	public ICollection<string>? Groups { get; set; }
	[JsonInclude, JsonPropertyName("model_plot_config")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfig? ModelPlotConfig { get; set; }
	[JsonInclude, JsonPropertyName("model_prune_window")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? ModelPruneWindow { get; set; }

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies the maximum period of time (in<br/>days) that snapshots are retained. This period is relative to the<br/>timestamp of the most recent snapshot for this job.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("model_snapshot_retention_days")]
	public long? ModelSnapshotRetentionDays { get; set; }

	/// <summary>
	/// <para>Settings related to how categorization interacts with partition fields.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("per_partition_categorization")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorization? PerPartitionCategorization { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. The period over which adjustments to the<br/>score are applied, as new data is seen.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("renormalization_window_days")]
	public long? RenormalizationWindowDays { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. The period of time (in days) that results<br/>are retained. Age is calculated relative to the timestamp of the latest<br/>bucket result. If this property has a non-null value, once per day at<br/>00:30 (server time), results that are the specified number of days older<br/>than the latest bucket result are deleted from Elasticsearch. The default<br/>value is null, which means all results are retained.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("results_retention_days")]
	public long? ResultsRetentionDays { get; set; }
}

/// <summary>
/// <para>Updates certain properties of an anomaly detection job.</para>
/// </summary>
public sealed partial class UpdateJobRequestDescriptor<TDocument> : RequestDescriptor<UpdateJobRequestDescriptor<TDocument>, UpdateJobRequestParameters>
{
	internal UpdateJobRequestDescriptor(Action<UpdateJobRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public UpdateJobRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningUpdateJob;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.update_job";

	public UpdateJobRequestDescriptor<TDocument> JobId(Elastic.Clients.Elasticsearch.Serverless.Id jobId)
	{
		RouteValues.Required("job_id", jobId);
		return Self;
	}

	private bool? AllowLazyOpenValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimit? AnalysisLimitsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor AnalysisLimitsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor> AnalysisLimitsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? BackgroundPersistIntervalValue { get; set; }
	private ICollection<string>? CategorizationFiltersValue { get; set; }
	private IDictionary<string, object>? CustomSettingsValue { get; set; }
	private long? DailyModelSnapshotRetentionAfterDaysValue { get; set; }
	private string? DescriptionValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Detector>? DetectorsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument> DetectorsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>> DetectorsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>>[] DetectorsDescriptorActions { get; set; }
	private ICollection<string>? GroupsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfig? ModelPlotConfigValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor<TDocument> ModelPlotConfigDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor<TDocument>> ModelPlotConfigDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? ModelPruneWindowValue { get; set; }
	private long? ModelSnapshotRetentionDaysValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorization? PerPartitionCategorizationValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor PerPartitionCategorizationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor> PerPartitionCategorizationDescriptorAction { get; set; }
	private long? RenormalizationWindowDaysValue { get; set; }
	private long? ResultsRetentionDaysValue { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. Specifies whether this job can open when<br/>there is insufficient machine learning node capacity for it to be<br/>immediately assigned to a node. If `false` and a machine learning node<br/>with capacity to run the job cannot immediately be found, the open<br/>anomaly detection jobs API returns an error. However, this is also<br/>subject to the cluster-wide `xpack.ml.max_lazy_ml_nodes` setting. If this<br/>option is set to `true`, the open anomaly detection jobs API does not<br/>return an error and the job waits in the opening state until sufficient<br/>machine learning node capacity is available.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> AllowLazyOpen(bool? allowLazyOpen = true)
	{
		AllowLazyOpenValue = allowLazyOpen;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> AnalysisLimits(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimit? analysisLimits)
	{
		AnalysisLimitsDescriptor = null;
		AnalysisLimitsDescriptorAction = null;
		AnalysisLimitsValue = analysisLimits;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> AnalysisLimits(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor descriptor)
	{
		AnalysisLimitsValue = null;
		AnalysisLimitsDescriptorAction = null;
		AnalysisLimitsDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> AnalysisLimits(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor> configure)
	{
		AnalysisLimitsValue = null;
		AnalysisLimitsDescriptor = null;
		AnalysisLimitsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The time between each periodic persistence<br/>of the model.<br/>The default value is a randomized value between 3 to 4 hours, which<br/>avoids all jobs persisting at exactly the same time. The smallest allowed<br/>value is 1 hour.<br/>For very large models (several GB), persistence could take 10-20 minutes,<br/>so do not set the value too low.<br/>If the job is open when you make the update, you must stop the datafeed,<br/>close the job, then reopen the job and restart the datafeed for the<br/>changes to take effect.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> BackgroundPersistInterval(Elastic.Clients.Elasticsearch.Serverless.Duration? backgroundPersistInterval)
	{
		BackgroundPersistIntervalValue = backgroundPersistInterval;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> CategorizationFilters(ICollection<string>? categorizationFilters)
	{
		CategorizationFiltersValue = categorizationFilters;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. Contains custom meta data about the job.<br/>For example, it can contain custom URL information as shown in Adding<br/>custom URLs to machine learning results.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> CustomSettings(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		CustomSettingsValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies a period of time (in days)<br/>after which only the first snapshot per day is retained. This period is<br/>relative to the timestamp of the most recent snapshot for this job. Valid<br/>values range from 0 to `model_snapshot_retention_days`. For jobs created<br/>before version 7.8.0, the default value matches<br/>`model_snapshot_retention_days`.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> DailyModelSnapshotRetentionAfterDays(long? dailyModelSnapshotRetentionAfterDays)
	{
		DailyModelSnapshotRetentionAfterDaysValue = dailyModelSnapshotRetentionAfterDays;
		return Self;
	}

	/// <summary>
	/// <para>A description of the job.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>An array of detector update objects.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> Detectors(ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Detector>? detectors)
	{
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsValue = detectors;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> Detectors(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument> descriptor)
	{
		DetectorsValue = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> Detectors(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>> configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptorAction = configure;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> Detectors(params Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>>[] configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>A list of job groups. A job can belong to no groups or many.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> Groups(ICollection<string>? groups)
	{
		GroupsValue = groups;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> ModelPlotConfig(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfig? modelPlotConfig)
	{
		ModelPlotConfigDescriptor = null;
		ModelPlotConfigDescriptorAction = null;
		ModelPlotConfigValue = modelPlotConfig;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> ModelPlotConfig(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor<TDocument> descriptor)
	{
		ModelPlotConfigValue = null;
		ModelPlotConfigDescriptorAction = null;
		ModelPlotConfigDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> ModelPlotConfig(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor<TDocument>> configure)
	{
		ModelPlotConfigValue = null;
		ModelPlotConfigDescriptor = null;
		ModelPlotConfigDescriptorAction = configure;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> ModelPruneWindow(Elastic.Clients.Elasticsearch.Serverless.Duration? modelPruneWindow)
	{
		ModelPruneWindowValue = modelPruneWindow;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies the maximum period of time (in<br/>days) that snapshots are retained. This period is relative to the<br/>timestamp of the most recent snapshot for this job.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> ModelSnapshotRetentionDays(long? modelSnapshotRetentionDays)
	{
		ModelSnapshotRetentionDaysValue = modelSnapshotRetentionDays;
		return Self;
	}

	/// <summary>
	/// <para>Settings related to how categorization interacts with partition fields.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> PerPartitionCategorization(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorization? perPartitionCategorization)
	{
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationValue = perPartitionCategorization;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> PerPartitionCategorization(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor descriptor)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor<TDocument> PerPartitionCategorization(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor> configure)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The period over which adjustments to the<br/>score are applied, as new data is seen.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> RenormalizationWindowDays(long? renormalizationWindowDays)
	{
		RenormalizationWindowDaysValue = renormalizationWindowDays;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The period of time (in days) that results<br/>are retained. Age is calculated relative to the timestamp of the latest<br/>bucket result. If this property has a non-null value, once per day at<br/>00:30 (server time), results that are the specified number of days older<br/>than the latest bucket result are deleted from Elasticsearch. The default<br/>value is null, which means all results are retained.</para>
	/// </summary>
	public UpdateJobRequestDescriptor<TDocument> ResultsRetentionDays(long? resultsRetentionDays)
	{
		ResultsRetentionDaysValue = resultsRetentionDays;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AllowLazyOpenValue.HasValue)
		{
			writer.WritePropertyName("allow_lazy_open");
			writer.WriteBooleanValue(AllowLazyOpenValue.Value);
		}

		if (AnalysisLimitsDescriptor is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, AnalysisLimitsDescriptor, options);
		}
		else if (AnalysisLimitsDescriptorAction is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor(AnalysisLimitsDescriptorAction), options);
		}
		else if (AnalysisLimitsValue is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, AnalysisLimitsValue, options);
		}

		if (BackgroundPersistIntervalValue is not null)
		{
			writer.WritePropertyName("background_persist_interval");
			JsonSerializer.Serialize(writer, BackgroundPersistIntervalValue, options);
		}

		if (CategorizationFiltersValue is not null)
		{
			writer.WritePropertyName("categorization_filters");
			JsonSerializer.Serialize(writer, CategorizationFiltersValue, options);
		}

		if (CustomSettingsValue is not null)
		{
			writer.WritePropertyName("custom_settings");
			JsonSerializer.Serialize(writer, CustomSettingsValue, options);
		}

		if (DailyModelSnapshotRetentionAfterDaysValue.HasValue)
		{
			writer.WritePropertyName("daily_model_snapshot_retention_after_days");
			writer.WriteNumberValue(DailyModelSnapshotRetentionAfterDaysValue.Value);
		}

		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		if (DetectorsDescriptor is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, DetectorsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorAction is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>(DetectorsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorActions is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			foreach (var action in DetectorsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else if (DetectorsValue is not null)
		{
			writer.WritePropertyName("detectors");
			JsonSerializer.Serialize(writer, DetectorsValue, options);
		}

		if (GroupsValue is not null)
		{
			writer.WritePropertyName("groups");
			JsonSerializer.Serialize(writer, GroupsValue, options);
		}

		if (ModelPlotConfigDescriptor is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, ModelPlotConfigDescriptor, options);
		}
		else if (ModelPlotConfigDescriptorAction is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor<TDocument>(ModelPlotConfigDescriptorAction), options);
		}
		else if (ModelPlotConfigValue is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, ModelPlotConfigValue, options);
		}

		if (ModelPruneWindowValue is not null)
		{
			writer.WritePropertyName("model_prune_window");
			JsonSerializer.Serialize(writer, ModelPruneWindowValue, options);
		}

		if (ModelSnapshotRetentionDaysValue.HasValue)
		{
			writer.WritePropertyName("model_snapshot_retention_days");
			writer.WriteNumberValue(ModelSnapshotRetentionDaysValue.Value);
		}

		if (PerPartitionCategorizationDescriptor is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationDescriptor, options);
		}
		else if (PerPartitionCategorizationDescriptorAction is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor(PerPartitionCategorizationDescriptorAction), options);
		}
		else if (PerPartitionCategorizationValue is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationValue, options);
		}

		if (RenormalizationWindowDaysValue.HasValue)
		{
			writer.WritePropertyName("renormalization_window_days");
			writer.WriteNumberValue(RenormalizationWindowDaysValue.Value);
		}

		if (ResultsRetentionDaysValue.HasValue)
		{
			writer.WritePropertyName("results_retention_days");
			writer.WriteNumberValue(ResultsRetentionDaysValue.Value);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>Updates certain properties of an anomaly detection job.</para>
/// </summary>
public sealed partial class UpdateJobRequestDescriptor : RequestDescriptor<UpdateJobRequestDescriptor, UpdateJobRequestParameters>
{
	internal UpdateJobRequestDescriptor(Action<UpdateJobRequestDescriptor> configure) => configure.Invoke(this);

	public UpdateJobRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningUpdateJob;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.update_job";

	public UpdateJobRequestDescriptor JobId(Elastic.Clients.Elasticsearch.Serverless.Id jobId)
	{
		RouteValues.Required("job_id", jobId);
		return Self;
	}

	private bool? AllowLazyOpenValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimit? AnalysisLimitsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor AnalysisLimitsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor> AnalysisLimitsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? BackgroundPersistIntervalValue { get; set; }
	private ICollection<string>? CategorizationFiltersValue { get; set; }
	private IDictionary<string, object>? CustomSettingsValue { get; set; }
	private long? DailyModelSnapshotRetentionAfterDaysValue { get; set; }
	private string? DescriptionValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Detector>? DetectorsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor DetectorsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor> DetectorsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor>[] DetectorsDescriptorActions { get; set; }
	private ICollection<string>? GroupsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfig? ModelPlotConfigValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor ModelPlotConfigDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor> ModelPlotConfigDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? ModelPruneWindowValue { get; set; }
	private long? ModelSnapshotRetentionDaysValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorization? PerPartitionCategorizationValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor PerPartitionCategorizationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor> PerPartitionCategorizationDescriptorAction { get; set; }
	private long? RenormalizationWindowDaysValue { get; set; }
	private long? ResultsRetentionDaysValue { get; set; }

	/// <summary>
	/// <para>Advanced configuration option. Specifies whether this job can open when<br/>there is insufficient machine learning node capacity for it to be<br/>immediately assigned to a node. If `false` and a machine learning node<br/>with capacity to run the job cannot immediately be found, the open<br/>anomaly detection jobs API returns an error. However, this is also<br/>subject to the cluster-wide `xpack.ml.max_lazy_ml_nodes` setting. If this<br/>option is set to `true`, the open anomaly detection jobs API does not<br/>return an error and the job waits in the opening state until sufficient<br/>machine learning node capacity is available.</para>
	/// </summary>
	public UpdateJobRequestDescriptor AllowLazyOpen(bool? allowLazyOpen = true)
	{
		AllowLazyOpenValue = allowLazyOpen;
		return Self;
	}

	public UpdateJobRequestDescriptor AnalysisLimits(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimit? analysisLimits)
	{
		AnalysisLimitsDescriptor = null;
		AnalysisLimitsDescriptorAction = null;
		AnalysisLimitsValue = analysisLimits;
		return Self;
	}

	public UpdateJobRequestDescriptor AnalysisLimits(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor descriptor)
	{
		AnalysisLimitsValue = null;
		AnalysisLimitsDescriptorAction = null;
		AnalysisLimitsDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor AnalysisLimits(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor> configure)
	{
		AnalysisLimitsValue = null;
		AnalysisLimitsDescriptor = null;
		AnalysisLimitsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The time between each periodic persistence<br/>of the model.<br/>The default value is a randomized value between 3 to 4 hours, which<br/>avoids all jobs persisting at exactly the same time. The smallest allowed<br/>value is 1 hour.<br/>For very large models (several GB), persistence could take 10-20 minutes,<br/>so do not set the value too low.<br/>If the job is open when you make the update, you must stop the datafeed,<br/>close the job, then reopen the job and restart the datafeed for the<br/>changes to take effect.</para>
	/// </summary>
	public UpdateJobRequestDescriptor BackgroundPersistInterval(Elastic.Clients.Elasticsearch.Serverless.Duration? backgroundPersistInterval)
	{
		BackgroundPersistIntervalValue = backgroundPersistInterval;
		return Self;
	}

	public UpdateJobRequestDescriptor CategorizationFilters(ICollection<string>? categorizationFilters)
	{
		CategorizationFiltersValue = categorizationFilters;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. Contains custom meta data about the job.<br/>For example, it can contain custom URL information as shown in Adding<br/>custom URLs to machine learning results.</para>
	/// </summary>
	public UpdateJobRequestDescriptor CustomSettings(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		CustomSettingsValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies a period of time (in days)<br/>after which only the first snapshot per day is retained. This period is<br/>relative to the timestamp of the most recent snapshot for this job. Valid<br/>values range from 0 to `model_snapshot_retention_days`. For jobs created<br/>before version 7.8.0, the default value matches<br/>`model_snapshot_retention_days`.</para>
	/// </summary>
	public UpdateJobRequestDescriptor DailyModelSnapshotRetentionAfterDays(long? dailyModelSnapshotRetentionAfterDays)
	{
		DailyModelSnapshotRetentionAfterDaysValue = dailyModelSnapshotRetentionAfterDays;
		return Self;
	}

	/// <summary>
	/// <para>A description of the job.</para>
	/// </summary>
	public UpdateJobRequestDescriptor Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>An array of detector update objects.</para>
	/// </summary>
	public UpdateJobRequestDescriptor Detectors(ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Detector>? detectors)
	{
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsValue = detectors;
		return Self;
	}

	public UpdateJobRequestDescriptor Detectors(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor descriptor)
	{
		DetectorsValue = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor Detectors(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor> configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptorAction = configure;
		return Self;
	}

	public UpdateJobRequestDescriptor Detectors(params Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor>[] configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>A list of job groups. A job can belong to no groups or many.</para>
	/// </summary>
	public UpdateJobRequestDescriptor Groups(ICollection<string>? groups)
	{
		GroupsValue = groups;
		return Self;
	}

	public UpdateJobRequestDescriptor ModelPlotConfig(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfig? modelPlotConfig)
	{
		ModelPlotConfigDescriptor = null;
		ModelPlotConfigDescriptorAction = null;
		ModelPlotConfigValue = modelPlotConfig;
		return Self;
	}

	public UpdateJobRequestDescriptor ModelPlotConfig(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor descriptor)
	{
		ModelPlotConfigValue = null;
		ModelPlotConfigDescriptorAction = null;
		ModelPlotConfigDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor ModelPlotConfig(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor> configure)
	{
		ModelPlotConfigValue = null;
		ModelPlotConfigDescriptor = null;
		ModelPlotConfigDescriptorAction = configure;
		return Self;
	}

	public UpdateJobRequestDescriptor ModelPruneWindow(Elastic.Clients.Elasticsearch.Serverless.Duration? modelPruneWindow)
	{
		ModelPruneWindowValue = modelPruneWindow;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option, which affects the automatic removal of old<br/>model snapshots for this job. It specifies the maximum period of time (in<br/>days) that snapshots are retained. This period is relative to the<br/>timestamp of the most recent snapshot for this job.</para>
	/// </summary>
	public UpdateJobRequestDescriptor ModelSnapshotRetentionDays(long? modelSnapshotRetentionDays)
	{
		ModelSnapshotRetentionDaysValue = modelSnapshotRetentionDays;
		return Self;
	}

	/// <summary>
	/// <para>Settings related to how categorization interacts with partition fields.</para>
	/// </summary>
	public UpdateJobRequestDescriptor PerPartitionCategorization(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorization? perPartitionCategorization)
	{
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationValue = perPartitionCategorization;
		return Self;
	}

	public UpdateJobRequestDescriptor PerPartitionCategorization(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor descriptor)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationDescriptor = descriptor;
		return Self;
	}

	public UpdateJobRequestDescriptor PerPartitionCategorization(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor> configure)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The period over which adjustments to the<br/>score are applied, as new data is seen.</para>
	/// </summary>
	public UpdateJobRequestDescriptor RenormalizationWindowDays(long? renormalizationWindowDays)
	{
		RenormalizationWindowDaysValue = renormalizationWindowDays;
		return Self;
	}

	/// <summary>
	/// <para>Advanced configuration option. The period of time (in days) that results<br/>are retained. Age is calculated relative to the timestamp of the latest<br/>bucket result. If this property has a non-null value, once per day at<br/>00:30 (server time), results that are the specified number of days older<br/>than the latest bucket result are deleted from Elasticsearch. The default<br/>value is null, which means all results are retained.</para>
	/// </summary>
	public UpdateJobRequestDescriptor ResultsRetentionDays(long? resultsRetentionDays)
	{
		ResultsRetentionDaysValue = resultsRetentionDays;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AllowLazyOpenValue.HasValue)
		{
			writer.WritePropertyName("allow_lazy_open");
			writer.WriteBooleanValue(AllowLazyOpenValue.Value);
		}

		if (AnalysisLimitsDescriptor is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, AnalysisLimitsDescriptor, options);
		}
		else if (AnalysisLimitsDescriptorAction is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AnalysisMemoryLimitDescriptor(AnalysisLimitsDescriptorAction), options);
		}
		else if (AnalysisLimitsValue is not null)
		{
			writer.WritePropertyName("analysis_limits");
			JsonSerializer.Serialize(writer, AnalysisLimitsValue, options);
		}

		if (BackgroundPersistIntervalValue is not null)
		{
			writer.WritePropertyName("background_persist_interval");
			JsonSerializer.Serialize(writer, BackgroundPersistIntervalValue, options);
		}

		if (CategorizationFiltersValue is not null)
		{
			writer.WritePropertyName("categorization_filters");
			JsonSerializer.Serialize(writer, CategorizationFiltersValue, options);
		}

		if (CustomSettingsValue is not null)
		{
			writer.WritePropertyName("custom_settings");
			JsonSerializer.Serialize(writer, CustomSettingsValue, options);
		}

		if (DailyModelSnapshotRetentionAfterDaysValue.HasValue)
		{
			writer.WritePropertyName("daily_model_snapshot_retention_after_days");
			writer.WriteNumberValue(DailyModelSnapshotRetentionAfterDaysValue.Value);
		}

		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		if (DetectorsDescriptor is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, DetectorsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorAction is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor(DetectorsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorActions is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			foreach (var action in DetectorsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DetectorDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (DetectorsValue is not null)
		{
			writer.WritePropertyName("detectors");
			JsonSerializer.Serialize(writer, DetectorsValue, options);
		}

		if (GroupsValue is not null)
		{
			writer.WritePropertyName("groups");
			JsonSerializer.Serialize(writer, GroupsValue, options);
		}

		if (ModelPlotConfigDescriptor is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, ModelPlotConfigDescriptor, options);
		}
		else if (ModelPlotConfigDescriptorAction is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.ModelPlotConfigDescriptor(ModelPlotConfigDescriptorAction), options);
		}
		else if (ModelPlotConfigValue is not null)
		{
			writer.WritePropertyName("model_plot_config");
			JsonSerializer.Serialize(writer, ModelPlotConfigValue, options);
		}

		if (ModelPruneWindowValue is not null)
		{
			writer.WritePropertyName("model_prune_window");
			JsonSerializer.Serialize(writer, ModelPruneWindowValue, options);
		}

		if (ModelSnapshotRetentionDaysValue.HasValue)
		{
			writer.WritePropertyName("model_snapshot_retention_days");
			writer.WriteNumberValue(ModelSnapshotRetentionDaysValue.Value);
		}

		if (PerPartitionCategorizationDescriptor is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationDescriptor, options);
		}
		else if (PerPartitionCategorizationDescriptorAction is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PerPartitionCategorizationDescriptor(PerPartitionCategorizationDescriptorAction), options);
		}
		else if (PerPartitionCategorizationValue is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationValue, options);
		}

		if (RenormalizationWindowDaysValue.HasValue)
		{
			writer.WritePropertyName("renormalization_window_days");
			writer.WriteNumberValue(RenormalizationWindowDaysValue.Value);
		}

		if (ResultsRetentionDaysValue.HasValue)
		{
			writer.WritePropertyName("results_retention_days");
			writer.WriteNumberValue(ResultsRetentionDaysValue.Value);
		}

		writer.WriteEndObject();
	}
}